package MyHashSet;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class Solution {
    class MyHashSet {
        private final static int BASE = 769;
        private LinkedList<Integer>[] data;

        public MyHashSet(){
            data = new LinkedList[BASE];
            for (int i = 0; i < BASE; i++) {
                data[i] = new LinkedList<>();
            }
        }
        public void add(int key){
            int h = hash(key);
            Iterator<Integer> iterator = data[h].iterator();
            while (iterator.hasNext()){
                Integer elment = iterator.next();
                if(elment == key){
                    return;
                }
            }
            data[h].offerLast(key);
        }
        public boolean contains(int key){
            int h = hash(key);
            Iterator<Integer> iterator = data[h].iterator();
            while (iterator.hasNext()){
                int element = iterator.next();
                if(element==key){
                    return true;
                }
            }
            return false;
        }
        public void remove(int key){
            int h = hash(key);
            Iterator<Integer> iterator = data[h].iterator();
            while (iterator.hasNext()){
                Integer element = iterator.next();
                if(element.equals(key)){
                    data[h].remove(element);
                    return;
                }
            }
        }
        private int hash(int key){
            return key%BASE;
        }
    }
}
